﻿using System;
using System.Collections.Generic;
using System.Text;
using Pixysoft.Framework.Noebe.Orm.Controller;
using Pixysoft.Framework.XSchEmA;

namespace Pixysoft.Framework.Noebe.Orm.testdriven
{
    class tc_004
    {
        //object
        public void test001()
        {
            string path = StringFilter.RegularPath(AppDomain.CurrentDomain.BaseDirectory) + "helloworld.mdb";

            NoebeConfiguration config = new NoebeConfiguration();
            config.DatabaseType = DatabaseType.Access;
            config.Filename = path;

            NoebeManager.Reload(config);

            string objName = ReflectHelper.GetInterfaceTypeName(typeof(Person));
            string tablename = MappingHelper.GetTableName(objName);
            Int64 sidvalue = 12;

            OrmCommandController.GetSchema(tablename);
            OrmCommandController.GetObjectTable(NoebeCommandHelper.GetNoebeCommand(), objName, sidvalue);
            OrmCommandController.DeleteObject(NoebeCommandHelper.GetNoebeCommand(), objName, sidvalue);
        }

        //valuelist
        public void test002()
        {
            string path = StringFilter.RegularPath(AppDomain.CurrentDomain.BaseDirectory) + "helloworld.mdb";

            NoebeConfiguration config = new NoebeConfiguration();
            config.DatabaseType = DatabaseType.Access;
            config.Filename = path;

            NoebeManager.Reload(config);

            List<string> list = new List<string>();
            list.Add("helloworld");

            string objectName = ReflectHelper.GetInterfaceTypeName(typeof(Person));
            string fieldname = "stringlist";
            Int64 sidvalue = 123;

            OrmCommandController.CreateLinkValueTable(objectName, fieldname, sidvalue, list, null);
            OrmCommandController.GetLinkValueTable(NoebeCommandHelper.GetNoebeCommand(), objectName, fieldname, sidvalue);
        }

        //objectlist 
        public void test003()
        {
            string path = StringFilter.RegularPath(AppDomain.CurrentDomain.BaseDirectory) + "helloworld.mdb";

            NoebeConfiguration config = new NoebeConfiguration();
            config.DatabaseType = DatabaseType.Access;
            config.Filename = path;

            NoebeManager.Reload(config);

            string objectName = ReflectHelper.GetInterfaceTypeName(typeof(Person));
            string fieldname = "OrmList";
            Int64 sidvalue = 123;

            List<Int64> rsids = new List<long>();
            rsids.Add(321);

            OrmCommandController.CreateLinkToTable(objectName, fieldname, sidvalue, rsids, null);
            OrmCommandController.GetLinkToTable(NoebeCommandHelper.GetNoebeCommand(), objectName, fieldname, sidvalue, ReflectHelper.GetInterfaceTypeName(typeof(Car)));
            OrmCommandController.RemoveFromList(NoebeCommandHelper.GetNoebeCommand(), objectName, fieldname, sidvalue, rsids);
            OrmCommandController.DeleteList(NoebeCommandHelper.GetNoebeCommand(), objectName, fieldname, sidvalue);
        }

        // select
        public void test004()
        {
            string path = StringFilter.RegularPath(AppDomain.CurrentDomain.BaseDirectory) + "helloworld.mdb";

            NoebeConfiguration config = new NoebeConfiguration();
            config.DatabaseType = DatabaseType.Access;
            config.Filename = path;

            NoebeManager.Reload(config);

            string objectName = ReflectHelper.GetInterfaceTypeName(typeof(Person));
            string fieldname = "OrmList";
            Int64 sidvalue = 123;

            string tObjectname = ReflectHelper.GetInterfaceTypeName(typeof(Car));
            string upkname = "StringValue";
            string upk = "321";

            OrmCommandController.GetSelectTable(NoebeCommandHelper.GetNoebeCommand(), objectName, fieldname, sidvalue, tObjectname, upkname, upk);


        }

    }
}
